//
//  AboutViewController.swift
//  worldexchange
//
//  Created by xionghao on 2019/4/2.
//  Copyright © 2019 xionghao. All rights reserved.
//

import UIKit
import RxSwift
import RxCocoa


class AboutViewController: QMUICommonTableViewController {
    
    
    
    let dispose = DisposeBag()
    var enableTrace = false
    
    var items:[UserCellItem] = [UserCellItem]()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "aboutLabel".localized()
        setupData()
        // Do any additional setup after loading the view.
    }
    
    
    func setupData(){
        items.removeAll()
        
        let company = UserCellItem()
        company.name = "公司简介".localized()
        company.action = {
            let vc = WebViewController()
            vc.type = 1
            vc.articleItem = aboutItem
            vc.hidesBottomBarWhenPushed = true
            self.navigationController?.pushViewController(vc, animated: true)
        }
        
        let  notice = UserCellItem()
        notice.name = "公司公告".localized()
        
        notice.action = {
            let vc = NoticeViewController()
            vc.hidesBottomBarWhenPushed = true
            self.navigationController?.pushViewController(vc, animated: true)
        }
        
        let contact = UserCellItem()
        contact.name = "联系我们".localized()
        
        contact.action = {
            let vc = ContactViewController()
            vc.hidesBottomBarWhenPushed = true
            self.navigationController?.pushViewController(vc, animated: true)
        }
        
        items.append(contentsOf: [company,notice,contact])
        
        
        
    }
    
    /*
     // MARK: - Navigation
     
     // In a storyboard-based application, you will often want to do a little preparation before navigation
     override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
     // Get the new view controller using segue.destination.
     // Pass the selected object to the new view controller.
     }
     */
    
}
extension AboutViewController {
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return items.count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let item = items[indexPath.row]
        var cell = tableView.dequeueReusableCell(withIdentifier: "normal-cell") as? QMUITableViewCell
        
        if cell == nil {
            cell = QMUITableViewCell(for: tableView, with: UITableViewCell.CellStyle.default, reuseIdentifier: "normal-cell")
        }
        cell?.textLabel?.text = item.name
        cell?.textLabel?.font = UIFont.systemFont(ofSize: 15)
        cell?.accessoryType = .disclosureIndicator
        return cell!
    }
    
    
    override  func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let action = items[indexPath.row]
        if action.action != nil {
            action.action!()
        }
        
    }
    
}
